package com.pub.util;

import java.lang.reflect.Field;
import java.util.HashMap;

public class MapUtil {
    //将Model转成HashMap
    public static HashMap<String, Object> returnObjectEmptyValue(Object model){
        HashMap<String,Object> map = new HashMap<>();
        Field[] fields = model.getClass().getDeclaredFields();
        for (Field field:fields) {
            String  key = field.getName();
            Object object = null;
            try {
                field.setAccessible(true);
                object = field.get(model);
            }catch (IllegalArgumentException e){

            }catch (IllegalAccessException e){

            }
            if(object == null || "null".equals(object)){
                object = " ";
            }
            map.put(key,object);
        }

        return map;
    }
}
